package math;

public enum BooleanConstant implements BooleanExpression {

  TRUE, FALSE;

  @Override
  public int countMembers() {
    return 1;
  }

  @Override
  public Expression simplify() {
    return this;
  }

  @Override
  public String toString() {
    switch (this) {
    case TRUE:
      return "true";
    case FALSE:
      return "false";
    default:
      throw new IllegalStateException();
    }
  }

  @Override
  public <R> R accept(ExpressionVisitor<R> visitor) {
    return visitor.visitBooleanConstant(this);
  }

  @Override
  public boolean matches(Expression expr) {
    if (expr instanceof BooleanConstant) {
      BooleanConstant eConst = (BooleanConstant) expr;
      return eConst.equals(this);
    } else
      return false;
  }

  @Override
  public BooleanExpression toDNF() {
    return this;
  }

  public BooleanConstant negate() {
    return this.equals(TRUE) ? FALSE : TRUE;
  }
}